package td;

import java.util.ArrayList;

import ui.VineTrapView;

/*
 * Class for VineTrap. In addition to it's parent it has a slowLevel to give how much does it slow
 * down enemies.
 * */
public class VineTrap extends Trap {
	//slowLevel for amount of slowing.
	public float slowLevel;
	public boolean doesDmg;
	
	public VineTrap(){
		super();
		this.cooldownTime=20;
		this.slowLevel=1;
		this.doesDmg=false;
		this.viewable = new VineTrapView(this);
	}
	
	public VineTrap(Field position) {
		super(position);
		this.cooldownTime=20;
		this.slowLevel=1;
		this.doesDmg=false;
		this.viewable = new VineTrapView(this);
	}
	
	/*Upgrades VineTrap with given magicstone.*/
	public void upgrade(MagicStones stone) {
		this.stone=stone;
		switch(stone){
		case Blue:
			ArrayList<Field> neighbours = this.position.neighbours;
			for(int i=0; i<neighbours.size(); i++){
				Field current = neighbours.get(i);
				if(current.isRoad && !current.hasTrap){
					current.addElement(new VineTrap(current));
					current.hasTrap=true;
				}
			}
			this.wasUpgraded=true;
			break;
		case Red:
			this.slowLevel=2;
			this.wasUpgraded=true;
			break;
		case Yellow:
			this.cooldownTime-=(this.cooldownTime/2);
			if(this.cooldownTime<0)
				this.cooldownTime=0;
			this.wasUpgraded=true;
			break;
		case Rainbow:
			this.doesDmg=true;
			this.wasUpgraded=true;
			break;
		}
	}
}
